//引入样式
require('../css/commonCss/normalize.css')
require('../css/commonCss/reset.css')
require('../css/commonCss/property.css')
require('../css/commonCss/basic.less')
require('../fonts/iconfont.css')

require('../css/introduction.less')
//引入axios
const axios = require('axios')
//weui—插件库
require('weui')
const weui = require('weui.js')

// 文档加载事件
document.addEventListener('DOMContentLoaded', function () {
    //0:获取元素
    const returnCourse = document.querySelector('.icon-xiangzuo') //返回课程训练页面
    const name = document.querySelector('#name') //训练课程类名
    const desc = document.querySelector('#desc') //训练课程介绍
    const calorie = document.querySelector('#calorie') //卡路里
    const time = document.querySelector('#time') //分钟
    const peoplenum = document.querySelector('#peoplenum') //多少人练过
    const instrument = document.querySelector('#instrument') //仪器
    const frequency = document.querySelector('#frequency') //练习频率
    const imgurl = document.querySelector('#imgurl') //头像
    const video = document.querySelector('#video') //视频
    const mask = document.querySelector('.mask') //蒙层
    const startBtn = document.querySelector('#startBtn') //开始训练按钮


    // console.log(returnCourse);
    // 返回上一个页面
    returnCourse.addEventListener('click',function(){
        history.go(-1)
    })
    // B页面接受参数
    let cid = sessionStorage.cid;
    // console.log(cid);
    axios.get("http://139.9.177.51:8099/sports/courseDetail?id=" + cid)
    .then(function(res){
        console.log(res.data.data);
        let data = res.data.data;
        //渲染单个内容
        name.textContent = data.name;
        desc.textContent = data.desc;
        calorie.textContent = data.calorie;
        time.textContent = data.time;
        peoplenum.textContent = data.peoplenum;
        instrument.textContent = data.instrument;
        frequency.textContent = data.frequency;
        imgurl.src = 'http://139.9.177.51:8099' + data.imgurl;

        // 把视频信息存储到会话存储
        sessionStorage.fragments = JSON.stringify(data.fragments)


        //获取视频对应内容
        let videoCont = data.fragments[0].videoUrl;
        // console.log("http://139.9.177.51:8099" + videoCont);
        video.src = "http://139.9.177.51:8099" + videoCont;
        mask.addEventListener('click',function(){
            // alert(1111)
            this.style.display = 'none'
            video.play();
        })
        video.addEventListener('click',function(){
            this.style.display = 'flex'
            video.pause();
        })
        video.addEventListener('ended',function(){
            mask.style.display = 'flex'
        })
    })


    //点击开始训练跳转到训练页面
    startBtn.addEventListener('click',function(){
        location.href = './classTrainTwo.html'
    })
})
